<template>
  <view class="hospital-detail">
    <!-- 顶部医院信息 -->
    <view class="hospital-info">
      <image class="hospital-img" :src="hospital.logo" mode="aspectFill"></image>
      <view class="info-content">
        <view class="hospital-name">{{ hospital.name }}</view>
        <view class="hospital-level">{{ hospital.level }}</view>
        <view class="hospital-address">
          <text class="iconfont icon-location"></text>
          <text>{{ hospital.address }}</text>
        </view>
      </view>
    </view>

    <!-- 科室列表 -->
    <view class="department-list">
      <view class="title">科室列表</view>
      <view 
        class="department-item" 
        v-for="dept in departments" 
        :key="dept.id"
        @tap="goToDepartment(dept.id)"
      >
        <text>{{ dept.name }}</text>
        <text class="iconfont icon-arrow-right"></text>
      </view>
    </view>
  </view>
</template>

<script>
import { getHospitalById } from '@/api/hospital'
import { getDepartmentsByHospitalId } from '@/api/department'

export default {
  data() {
    return {
      hospital: {},
      departments: []
    }
  },
  onLoad(options) {
    const hospitalId = options.id
    this.getHospitalDetail(hospitalId)
    this.getDepartments(hospitalId)
  },
  methods: {
    // 获取医院详情
    async getHospitalDetail(id) {
      try {
        const res = await getHospitalById(id)
        this.hospital = res
      } catch (error) {
        uni.showToast({
          title: '获取医院信息失败',
          icon: 'none'
        })
      }
    },
    // 获取科室列表
    async getDepartments(hospitalId) {
      try {
        const res = await getDepartmentsByHospitalId(hospitalId)
        this.departments = res
      } catch (error) {
        uni.showToast({
          title: '获取科室列表失败',
          icon: 'none'
        })
      }
    },
    // 跳转到科室详情
    goToDepartment(deptId) {
      uni.navigateTo({
        url: `/pages/department/detail?id=${deptId}`
      })
    }
  }
}
</script>

<style lang="scss">
.hospital-detail {
  min-height: 100vh;
  background: #f5f5f5;
  
  .hospital-info {
    display: flex;
    padding: 30rpx;
    background: #fff;
    margin-bottom: 20rpx;
    
    .hospital-img {
      width: 160rpx;
      height: 160rpx;
      border-radius: 8rpx;
      margin-right: 24rpx;
    }
    
    .info-content {
      flex: 1;
      
      .hospital-name {
        font-size: 32rpx;
        font-weight: bold;
        color: #333;
        margin-bottom: 12rpx;
      }
      
      .hospital-level {
        display: inline-block;
        font-size: 24rpx;
        color: #007AFF;
        background: rgba(0, 122, 255, 0.1);
        padding: 4rpx 12rpx;
        border-radius: 4rpx;
        margin-bottom: 12rpx;
      }
      
      .hospital-address {
        font-size: 26rpx;
        color: #666;
        display: flex;
        align-items: center;
        
        .iconfont {
          font-size: 28rpx;
          margin-right: 6rpx;
          color: #999;
        }
      }
    }
  }
  
  .department-list {
    background: #fff;
    padding: 0 30rpx;
    
    .title {
      font-size: 32rpx;
      font-weight: bold;
      color: #333;
      padding: 30rpx 0;
      border-bottom: 1rpx solid #eee;
    }
    
    .department-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 30rpx 0;
      border-bottom: 1rpx solid #eee;
      
      text {
        font-size: 28rpx;
        color: #333;
        
        &.iconfont {
          color: #999;
          font-size: 24rpx;
        }
      }
      
      &:active {
        background: #f9f9f9;
      }
    }
  }
}
</style> 